import { getSurveyList, getSurveyDetail, saveSurvey, changeStatus, copySurvey, remindSurvey, deleteSurvey, getCycleList, downloadSurvey } from '@/services/survey';
import { filterObj } from '@/utils';
export default {
  name: 'survey',
  namespaced: true,
  state: {
    surveyListSource: null,
    surveyDetailSource: null,
    saveSurveySource: null,
    changeStatusSource: null,
    copySurveySource: null,
    remindSurveySource: null,
    deleteSurveySource: null,
    downloadSurveySource: null,
    cycleListSource: null
  },
  mutations: {
    setSurveyList(state, val) {
      state.surveyListSource = val;
    },
    setSurveyDetail(state, val) {
      state.surveyDetailSource = val;
    },
    setSaveSurvey(state, val) {
      state.saveSurveySource = val;
    },
    setChangeStatus(state, val) {
      state.changeStatusSource = val;
    },
    setCopySurvey(state, val) {
      state.copySurveySource = val;
    },
    setRemindSurvey(state, val) {
      state.remindSurveySource = val;
    },
    setDeleteSurvey(state, val) {
      state.deleteSurveySource = val;
    },
    setDownloadSurvey(state, val) {
      state.downloadSurveySource = val;
    },
    setCycleList(state, val) {
      state.cycleListSource = val;
    }
  },
  actions: {
    async getSurveyList({ commit }, params) {
      await getSurveyList(filterObj(params)).then(res => {
        commit('setSurveyList', res.data || null)
      }).catch(() => {
        commit('setSurveyList', null)
      })
    },
    async getSurveyDetail({ commit }, params) {
      await getSurveyDetail(filterObj(params)).then(res => {
        commit('setSurveyDetail', res.data || null)
      }).catch(() => {
        commit('setSurveyDetail', null)
      })
    },
    async saveSurvey({ commit }, params) {
      await saveSurvey(filterObj(params)).then(res => {
        commit('setSaveSurvey', res.data || null)
      }).catch(() => {
        commit('setSaveSurvey', null)
      })
    },
    async changeStatus({ commit }, params) {
      await changeStatus(filterObj(params)).then(res => {
        commit('setChangeStatus', res.data || null)
      }).catch(() => {
        commit('setChangeStatus', null)
      })
    },
    async copySurvey({ commit }, params) {
      await copySurvey(filterObj(params)).then(res => {
        commit('setCopySurvey', res.data || null)
      }).catch(() => {
        commit('setCopySurvey', null)
      })
    },
    async remindSurvey({ commit }, params) {
      await remindSurvey(filterObj(params)).then(res => {
        commit('setRemindSurvey', res.data || null)
      }).catch(() => {
        commit('setRemindSurvey', null)
      })
    },
    async deleteSurvey({ commit }, params) {
      await deleteSurvey(params).then(res => {
        commit('setDeleteSurvey', res.data || null)
      }).catch(() => {
        commit('setDeleteSurvey', null)
      })
    },
    async downloadSurvey({ commit }, params) {
      await downloadSurvey(filterObj(params)).then(res => {
        commit('setDownloadSurvey', res || null)
      }).catch(() => {
        commit('setDownloadSurvey', null)
      })
    },
    async getCycleList({ commit }, params) {
      await getCycleList(params).then(res => {
        commit('setCycleList', res.data || null)
      }).catch(() => {
        commit('setCycleList', null)
      })
    }
  }
}